package com.mengya.async;

import java.util.List;

import android.os.AsyncTask;
import android.widget.Toast;

import com.common.utils.mapper.JsonMapper;
import com.gzcwt.entity.Notice;
import com.gzcwt.entity.QueryPublicInfoResult;
import com.mengya.ui.MainActivity;
import com.mengya.utils.NoticeDBO;

public class NoticeUpdate extends AsyncTask<String, String, String> {
	NoticeDBO ndbo = new NoticeDBO();
	String result;

	public NoticeUpdate(String result) {
		this.result = result;
	}

	@Override
	protected void onPostExecute(String result) {
		// TODO Auto-generated method stub
		if (null == result) {
			System.out.println("lance 网络好像超时了哦");
		}
		ndbo.closeDB();
		super.onPostExecute(result);
	}

	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub

		ndbo.createDB(MainActivity.mainContext);
		super.onPreExecute();
	}

	@Override
	protected String doInBackground(String... arg0) {
		// TODO Auto-generated method stub
		JsonMapper json = JsonMapper.buildNormalMapper();
		QueryPublicInfoResult d2 = json.fromJson(result,
				QueryPublicInfoResult.class);
		if (null != d2) {
			List<Notice> publicinfos = d2.publicinfos;
			if (null != publicinfos && publicinfos.size() > 0) {
				if (publicinfos.size() > 0) {
					for (int i = 0; i < publicinfos.size(); i++) {
						ndbo.insertIntoNotice(publicinfos.get(i));
					}
				}
				return "done";
			}
		}
		return null;
	}

}